package client.control;

import base.BaseValue;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
  * @Description 购买记录有关接口封装
  * @author 孔明浩
  * @Date 2020/4/8
  */
public class RecordControl {
    RecordControl(){}
    public ResponseEntity getRecordOfStore(String token, Date start, Date end){
        ConnectControl connectControl = new ConnectControl();
        Map<String, String> map = new HashMap<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        map.put("start", simpleDateFormat.format(start));
        map.put("end",simpleDateFormat.format(end));
        connectControl.doPost(BaseValue.load + "getRecordOfStore", token, map);
        return ResponseEntity.fit(connectControl);
    }

    public ResponseEntity getRecordOfStore(String token,String start, String end){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try{
            return getRecordOfStore(token,
                    simpleDateFormat.parse(start + " 00:00"),
                    simpleDateFormat.parse(end + " 23:59"));
        } catch (ParseException e){
            e.printStackTrace();
        }
        return new ResponseEntity();
    }

    public ResponseEntity getRecordOfUser(String token){
        ConnectControl connectControl = new ConnectControl();
        connectControl.doPost(BaseValue.load + "getRecordOfUser", token, null);
        return ResponseEntity.fit(connectControl);
    }
}
